#pragma once
#include <string>
#include <vector>
#include "huffman.hpp"

using std::string;

struct FreqInfo {
	unsigned char _ch;
	size_t _appareCount;
	string _enCode;

	FreqInfo(size_t appareCount = 0)
		:_appareCount(appareCount)
	{}

	FreqInfo operator+(const FreqInfo& other) const {
		return FreqInfo(_appareCount + other._appareCount);
	}

	bool operator>(const FreqInfo& other) const {
		return _appareCount > other._appareCount;
	}

	bool operator== (const FreqInfo& other) const {
		return _appareCount == other._appareCount;
	}

	bool operator!= (const FreqInfo& other) const {
		return _appareCount != other._appareCount;
	}
};

class HuffmanCompress {
public:
	HuffmanCompress();
	void CompressFile(const string& filePath, string outPath = string());
	void DeCmpressFile(const string& filePath, string name = string());

	void GetHuffmanCode(HuffmanTreeNode<FreqInfo>* root);
	void enCode(HuffmanTreeNode<FreqInfo>* root);

	void PutsHead(const string& filePath, FILE* fOut);
	string GetsFileTail(const string& filePath);

	std::vector<FreqInfo> _status;
};